package com.ubs.training.server.dao.model;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;


import javax.persistence.*;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: xubuntu

 * Date: 8/21/12
 * Time: 2:06 AM
 * To change this template use File | Settings | File Templates.
 */
@GenericGenerator(name = "CMSTR_SEQ", strategy = "sequence",
        parameters = {@Parameter(name="sequence", value="cmstr_seq")})
@Entity
@Table(name="products",
        uniqueConstraints = {@UniqueConstraint(columnNames={"id_product"})}
)
public class Product {
    @GeneratedValue(generator = "CMSTR_SEQ")
    @Id
    private int id_product;


    private String name_product;

    private int status;

    private Date start_date;


    private int country;

    private int type_product;

    private int clientId;

    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, targetEntity = Client.class)
    @JoinColumn(name = "clientId")
    public int getClientId() {
        return clientId;
    }

    public void setClientId(int clientId) {
        this.clientId = clientId;
    }
    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, targetEntity = Type.class)
    @JoinColumn(name = "type_product")
    public int getType_product() {
        return type_product;
    }

    public void setType_product(int type_product) {
        this.type_product = type_product;
    }
    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, targetEntity = Country.class)
    @JoinColumn(name = "country")
    public int getCountry() {

        return country;
    }

    public void setCountry(int country) {
        this.country = country;
    }

    public Date getStart_date() {

        return start_date;
    }

    public void setStart_date(Date start_date) {
        this.start_date = start_date;
    }

    public int getStatus() {

        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }



    public int getId_product() {
        return id_product;
    }

    public void setId_product(int id_product) {
        this.id_product = id_product;
    }

    public String getName_product() {
        return name_product;
    }

    public void setName_product(String name_product) {
        this.name_product = name_product;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        Product product = (Product) o;

        if (clientId != product.clientId){
            return false;
        }
        if (country != product.country){
            return false;
        }
        if (id_product != product.id_product){
            return false;
        }
        if (status != product.status){
            return false;
        }
        if (type_product != product.type_product){
            return false;
        }
        if (name_product != null ? !name_product.equals(product.name_product) : product.name_product != null){
            return false;
        }

        if (start_date != null ? !start_date.equals(product.start_date) : product.start_date != null){
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int result = id_product;
        result = 31 * result + (name_product != null ? name_product.hashCode() : 0);
        result = 31 * result + status;
        result = 31 * result + (start_date != null ? start_date.hashCode() : 0);
        result = 31 * result + country;
        result = 31 * result + type_product;
        result = 31 * result + clientId;
        return result;
    }
}
